package yl.hs.bmipfull.service.salemanage.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yl.hs.bmipfull.daos.salemanage.ICustomerUserDao;
import yl.hs.bmipfull.daos.salemanage.ILinkerInfoDao;
import yl.hs.bmipfull.pojo.salemanage.CustomerInfoEntity;
import yl.hs.bmipfull.pojo.salemanage.CustomerUserEntity;
import yl.hs.bmipfull.pojo.salemanage.SaleContractEntity;
import yl.hs.bmipfull.service.salemanage.ICustomUserService;
import yl.hs.bmipfull.utils.Tl;

import java.util.List;
import java.util.Map;

/*
 * CustomUserServiceImpl
 * @category
 * @author 谢景广
 * @date 2022-04-21
 */
@Service
public class CustomUserServiceImpl extends SaleBaseService implements ICustomUserService {
    @Autowired
    ICustomerUserDao userDao;
    @Autowired
    ILinkerInfoDao linkerInfoDao;

    @Override
    public CustomerUserEntity findByCustSNAndLinkSN(String linkSN, String objSN) {
        return userDao.findByCustSNAndLinkSN(linkSN,objSN);
    }

    @Override
    public String save(Map<String, Object> model, String sn) {

            try {
                if (Tl.isEmpty(sn)){
                    CustomerUserEntity entity=new CustomerUserEntity();
                    Tl.getChangeLog(entity, model);
                    entity.setSn(queryNewSN(CustomerUserEntity.class));
                    entity.setObjType(Tl.getDBMapCode(SaleContractEntity.class));
                    userDao.insertNew(entity);
                    return entity.getSn();
                }else{
                    var entity=userDao.findBySN(sn);
                    Tl.getChangeLog(entity, model);
                    userDao.update(entity);
                    return entity.getSn();
                }
            } catch (Exception e) {
                e.printStackTrace();
                return "";
            }
    }

    @Override
    public Integer deleteBySn(String sn) {
        return userDao.deleteBySN(sn);
    }
}
